#include "stdafx.h"
#include "Logger.h"

Logger::Logger()
{

}

Logger::Logger(std::string fileName)
{
	this->mFileName = fileName;
}

Logger::~Logger()
{
	End();
}

bool Logger::Start()
{
	if (mFlieStream.is_open())
	{
		mFlieStream.close();
	}
	if (mFileName.empty())
	{
		return false;
	}
	mFlieStream.open(mFileName.c_str(), std::ios::out | std::ios::app);
	if (mFlieStream.is_open())
	{
		return true;
	}
	return false;
}

bool Logger::End()
{
	if (mFlieStream.is_open())
	{
		mFlieStream.close();
	}
	return true;
}

void Logger::SetLogFileName(std::string fileName)
{
	this->mFileName = fileName;
}

bool Logger::log(std::string content)
{
	if (mFlieStream.is_open())
	{
		mFlieStream.write(content.c_str(), content.length());
		mFlieStream.flush();
		return true;
	}
	else
	{
		if (Start())
		{
			mFlieStream.write(content.c_str(), content.length());
			mFlieStream.flush();
			return true;
		}
	}
	return false;
}